package tv.youxing.android.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import java.util.ArrayList;
import java.util.List;

import tv.youxing.android.R;
import tv.youxing.android.entity.FriendModel;
import tv.youxing.android.ui.AdvertisementWEBActivity;
import tv.youxing.android.utils.PicassoUtils;

/**
 * Created by Administrator on 2017/6/20.
 */

public class AbsRecyclerAdater extends RecyclerView.Adapter {



    List<FriendModel.ResultBean.AdsBean> mAdsBeanList = new ArrayList<>();
    Context mContext;

    public AbsRecyclerAdater(List<FriendModel.ResultBean.AdsBean> adsBeanList, Context context) {
        mAdsBeanList = adsBeanList;
        mContext = context;

        for (int i = 0; i < mAdsBeanList.size(); i++) {

//            L.d(mAdsBeanList.get(i).getCover());

        }
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        final Holder h = new Holder(LayoutInflater.from(parent.getContext()).inflate(R.layout.friend_abs_item,parent,false));

        return h;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        PicassoUtils.loadImageView(mContext,mAdsBeanList.get(position).getCover(),((Holder)holder).iv);

        ((Holder)holder).iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                Intent intent = new Intent(mContext, AdvertisementDetailsActivity.class);
//                intent.putExtra("ad_id",mAdsBeanList.get(position).getAd_id()+"");
//                mContext.startActivity(intent);


                Intent intent = new Intent(mContext, AdvertisementWEBActivity.class);
                intent.putExtra("url",mAdsBeanList.get(position).getGo_to_url()+"");
                mContext.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mAdsBeanList==null || mAdsBeanList.size()==0 ? 0 : mAdsBeanList.size();
    }


    class Holder extends RecyclerView.ViewHolder{

        ImageView iv;

        public Holder(View itemView) {
            super(itemView);

            iv = (ImageView) itemView.findViewById(R.id.imageView);
        }
    }
}
